package mc.support.orm.shard.sql.comm;

import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLStatement;
import mc.support.orm.shard.ShardStrategy;

/**
 * Created with IntelliJ IDEA. <br/>
 * Author: Francis Yuen    <br/>
 * Date: 2014-10-15  <br/>
 */
public abstract class AbstractSqlPhaser implements SqlPhaser {

    @Override
    public String phase( SQLStatement statement, Object params, String mapperId, ShardStrategy strategy ) {
        return doDeParse( doPhase( statement, params, mapperId, strategy ) );
    }

    /**
     * deparse statement to sql string
     *
     * @param statement
     * @return
     */
    protected String doDeParse( SQLStatement statement ) {
        return SQLUtils.toMySqlString( statement );
    }

    abstract protected SQLStatement doPhase( SQLStatement statement, Object params, String mapperId, ShardStrategy strategy );

}
